package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.services.infrastructure.bean.OrderDeliveryBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.OrderDeliveryMapper;
import com.molichuxing.services.infrastructure.dto.request.create.OrderDeliveryCreateDto;
import com.molichuxing.services.infrastructure.dto.response.OrderDeliveryDto;
import com.molichuxing.services.infrastructure.service.OrderDeliveryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 订单提车表 服务实现类
 * </p>
 *
 * @author renzhengyu
 * @since 2019-08-12
 */
@Service("orderDeliveryService")
public class OrderDeliveryServiceImpl implements OrderDeliveryService {
    private static final Logger logger = LoggerFactory.getLogger(OrderDeliveryServiceImpl.class);

    @Autowired
    private OrderDeliveryMapper orderDeliveryMapper;

    /**
     * 查询提单交车信息
     *
     * @param orderCode 订单号
     * @return
     */
    @Override
    public OrderDeliveryDto getOrderDelivery(Long orderCode) {
        return Convert.toOrderDeliveryDto(orderDeliveryMapper.getByOrderCode(orderCode));
    }

    /**
     * 查询订单交车信息
     *
     * @param orderCodes 订单号
     * @return
     */
    @Override
    public Map<Long, OrderDeliveryDto> getOrderDelivery(List<Long> orderCodes) {
        List<OrderDeliveryBean> deliveryBeans = orderDeliveryMapper.getByOrderCodes(orderCodes);
        return deliveryBeans == null ? null :
                deliveryBeans.stream()
                        .collect(Collectors.toMap(OrderDeliveryBean::getOrderCode, bean -> Convert.toOrderDeliveryDto(bean)));
    }

    /**
     * 新增提车表信息
     *
     * @param createDto
     * @return
     */
    @Override
    public Boolean create(OrderDeliveryCreateDto createDto) {
        orderDeliveryMapper.create(Convert.toOrderDeliveryBean(createDto));
        return true;
    }

}
